<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="dj.pageModel.PcompanyReport" %>
<script type="text/javascript">
	function editCompanyReport(id) {
		if(id) {
			$('<div/>').dialog({
				href : "${pageContext.request.contextPath}/companyReportAction!toReportPage.action?id=" + id,
				width : 800,
				height : 670,
				iconCls : 'icon-compose',
				modal : true,
				title : '报表',
				buttons : [ {
					text : '提交',
					iconCls : 'icon-redo',
					handler : function() {
						var d = $(this).closest('.window-body');
						$.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/companyReportAction!saveReport.action",
							dataType : "json",
							beforeSend : function() {
								var isValid = $("#company-datareport-report-form").form('validate');
								if (isValid) {
									$.messager.progress({
										text : "提交数据，请等待..."
									});
								}
								return isValid;
							},
							data : $("#company-datareport-report-form").serialize() + "&id=" + id + "&status=<%=PcompanyReport.STRUTS_未审核 %>",
							error : function(info) {
								$.messager.progress('close');
								eval(info.responseText);
							},
							success : function(result) {
								$.messager.show({
									msg : result.msg,
									title : '提示'
								});
								$.messager.progress('close');
								if(result.success) {
									$('#company-datareport-write-list-dg').datagrid('reload');
									d.dialog('destroy');
								}
							}
						});
					}
				}, {
					text : '保存',
					iconCls : 'icon-save',
					handler : function() {
						var d = $(this).closest('.window-body');
						$.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/companyReportAction!saveReport.action",
							dataType : "json",
							beforeSend : function() {
								var isValid = $("#company-datareport-report-form").form('validate');
								if (isValid) {
									$.messager.progress({
										text : "提交数据，请等待..."
									});
								}
								return isValid;
							},
							data : $("#company-datareport-report-form").serialize() + "&id=" + id,
							error : function(info) {
								$.messager.progress('close');
								eval(info.responseText);
							},
							success : function(result) {
								$.messager.show({
									msg : result.msg,
									title : '提示'
								});
								$.messager.progress('close');
								if(result.success) {
									$('#company-datareport-write-list-dg').datagrid('reload');
									d.dialog('destroy');
								}
							}
						});
					}
				} ],
				onClose : function() {
					$(this).dialog('destroy');
				}
			});
		} else {
			$.messager.alert('提示','没有可编辑的对象！'); 
		}
	}

	//查询功能
	function searchReportWrite() {
		$("#company-datareport-write-list-dg").datagrid("options").queryParams = getQueryParams("company-datareport-write-search");
		autoLoad($("#company-datareport-write-list-dg").datagrid("getPager"), 1);
	}

	$(function() {
		$('#company-datareport-write-list-dg').datagrid({
			url : "${pageContext.request.contextPath }/companyReportAction!getCompanyReportListByCompany.action",
			onLoadError : function(retValue) {
				eval(retValue.responseText);
			},
			singleSelect : true,
			selectOnCheck : true,
			pagination : true,
			fitColumns : true,
			pageSize : 10,
			pageList : [ 5, 10, 15, 20 ],
			nowrap : true,
			border : false,
			singleSelect : false,
			idField : 'id',
			frozenColumns : [ [ {
				field : 'id',
				width : 50,
				checkbox : true
			} ] ],
			columns : [ [ {
				field : 'taskmonth',
				title : '月份',
				width : 100
			}, {
				field : 'startDate',
				title : '开始日期',
				width : 120
			}, {
				field : 'endDate',
				title : '结束日期',
				width : 120
			}, {
				field : 'status',
				title : '当前状态',
				width : 80,
				formatter : function(value) {
					if(value == '<%=PcompanyReport.STRUTS_未填写 %>') {
						return "未填写";
					}
					if(value == '<%=PcompanyReport.STRUTS_未提交 %>') {
						return "未提交";
					}
					if(value == '<%=PcompanyReport.STRUTS_未通过 %>') {
						return "未通过";
					}
				}
			}, {
				field : 'operate',
				title : '操作',
				width : 80,
				align : 'center',
				formatter : function(value, rowData, rowIndex) {
					return "<a href='javascript:void(0)' onclick='editCompanyReport(\"" + rowData.id + "\");'><img src='${pageContext.request.contextPath }/images/pencil.png' oncl border='0'></a>";
				}
			} ] ]
		});
	});
</script>
<div class="easyui-layout" data-options="fit:true">

	<div data-options="region:'north', title:'查询', iconCls: 'icon-search'" style="height:80px; padding: 0;">
		<div style="padding-top: 10px; padding-left: 20px">
			<form id="company-datareport-write-search">
				<span>月份：<input type="text" id="company-datareport-write-month" name="taskmonth" onclick="WdatePicker({dateFmt:'yyyy-MM', minDate:'%y-%M'})"></span>&nbsp;&nbsp;
				<span><a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchReportWrite()" data-options="iconCls:'icon-search'">查询</a></span>
			</form>
		</div>
	</div>

	<div data-options="region:'center', title:'数据录入列表', iconCls: 'icon-group'" style="padding: 0;">
		<table id="company-datareport-write-list-dg"></table>
	</div>

</div>
